package hkr.vfu.bluecenter.backend;

import java.lang.ref.WeakReference;

import hkr.vfu.bluecenter.swipe_fragments.UpdateUIListener;

/**
 * Created by mattiasbowallius on 15/01/14.
 */
public class BluetoothTask implements BluetoothRunnable.TaskRunnableBluetoothMethods {
    private Thread mThreadThis;
    private WeakReference<UpdateUIListener> updateUIListenerWeakReference;
    private BluetoothRunnable bluetoothRunnable;
    private BluetoothManager bluetoothManager;
    private String command;
    private String macAddress;

    public BluetoothTask() {
        bluetoothRunnable = new BluetoothRunnable(this);
    }

    public UpdateUIListener getUpdateUIListener() {
        if (updateUIListenerWeakReference != null) {
            return updateUIListenerWeakReference.get();
        }
        return null;
    }

    public void initializeBluetoothTask(BluetoothManager instance, UpdateUIListener updateUIListener) {
        updateUIListenerWeakReference = new WeakReference<UpdateUIListener>(updateUIListener);
        bluetoothManager = instance;
    }

    public void recycle() {
        if (updateUIListenerWeakReference != null) {
            updateUIListenerWeakReference.clear();
            updateUIListenerWeakReference = null;
        }
    }

    public BluetoothRunnable getCommandRunnable() {
        return bluetoothRunnable;
    }

    public Thread getBluetoothThread() {
        return mThreadThis;
    }

    public void setBluetoothThread(Thread currentThread) {
        this.mThreadThis = currentThread;
    }

    @Override
    public String getCommand() {
        return command;
    }

    public void setCommand(String command) {
        this.command = command;
    }

    public BluetoothManager getBluetoothManager() {
        return bluetoothManager;
    }

    public String getMacAddress() {
        return macAddress;
    }

    public void setMacAddress(String macAddress) {
        this.macAddress = macAddress;
    }
}
